﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;

namespace HQWeb.View
{
    /// <summary>
    /// GetDetialProjectshx 的摘要说明
    /// </summary>
    public class GetDetialProjectshx : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string strProjectID = context.Request["id"];
            context.Response.Write(strGetResout(strProjectID));
        }

        private string strGetResout(string strProjectID)
        {
            StringBuilder strHtml = new StringBuilder();
            BLL.Progect.T_PUB_PROJECT projectBll = new BLL.Progect.T_PUB_PROJECT();
            Model.Progect.T_PUB_PROJECT projectModel = projectBll.GetModel(strProjectID);
            if (projectModel != null)
            {
                strHtml.Append("<table width=\"100%\"> ");

                strHtml.Append(" <tr> <td align=\"right\" style=\"width:30%\">服务项目名称:</td>");


                strHtml.Append(string.Format("<td align=\"left\"> {0}</td>  </tr>", projectModel.PROJECT_NAME));
                strHtml.Append(" <tr>  <td align=\"right\">  所属分类：</td>");
                string strTypeName = "";
                #region 获得类型名称
                int intYypeId = projectModel.PROJECTTYPE_ID == null ? 0 : Convert.ToInt32(projectModel.PROJECTTYPE_ID);
                BLL.SysManage.T_PUB_PROJECTTYPE TypeBll = new BLL.SysManage.T_PUB_PROJECTTYPE();
                Model.SysManage.T_PUB_PROJECTTYPE typeModel = TypeBll.GetModel(intYypeId);
                if (typeModel != null)
                {
                    strTypeName = typeModel.PROJECTTYPE_NAME;
                }
                #endregion
                strHtml.Append(string.Format("<td align=\"left\">{0} </td> </tr>", strTypeName));

                strHtml.Append("   <tr>  <td align=\"right\"> 价 格：</td>");
                strHtml.Append(string.Format(" <td align=\"left\">{0}</td> </tr>", projectModel.PRICE));

                strHtml.Append("   <tr>  <td align=\"right\"> 说 明：</td>");

                strHtml.Append(string.Format(" <td align=\"left\">{0}</td> </tr>", projectModel.REMARK));
                #region 获得包含元素
                BLL.Progect.T_PUB_PROJECTMATERIAL bll = new BLL.Progect.T_PUB_PROJECTMATERIAL();
                DataTable modelList = bll.GetModelListByPid(strProjectID).Tables[0];
                int count = modelList.Rows.Count;
                string strMateralNamel;
                string strNum;
                string strRemark;
                strHtml.Append("  <tr> <td colspan=\"2\">  <div align=\"center\">");
                strHtml.Append(" <div style=\"text-align: left; padding-left: 50px; padding-top: 5px;\"> 包含元素： </div> <div>");

                for (int i = 0; i < count; i++)
                {
                    strMateralNamel = modelList.Rows[i]["MATERIAL_NAME"].ToString();
                    strNum = modelList.Rows[i]["NUM"].ToString();
                    strRemark = modelList.Rows[i]["REMARK"].ToString();

                    strHtml.Append(" <hr />");
                    strHtml.Append("  <table width=\"100%\" >");
                    strHtml.Append("<tr> <td align=\"right\" style=\"width:20%\">   元素名称：</td>");

                    strHtml.Append(string.Format("<td align=\"left\">{0} </td> </tr>", strMateralNamel));

                    strHtml.Append(" <tr>  <td align=\"right\">数量：</td>");
                    strHtml.Append(string.Format("<td align=\"left\">{0} </td> </tr>", strNum));

                    strHtml.Append(" <tr>  <td align=\"right\">说明：</td>");
                    strHtml.Append(string.Format("<td align=\"left\">{0} </td> </tr>", strRemark));
                    strHtml.Append("</table>");
                }
                strHtml.Append(" </div>  </div>  </td>   </tr> </table>");




                #endregion
            }
            return strHtml.ToString(); ;
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}